package com.demdevdudes.disch.gamestates;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.math.Vector3;
import com.demdevdudes.disch.gameobjects.GameObject;
import com.demdevdudes.disch.gameobjects.GameObjectTest;
import com.demdevdudes.disch.helpers.SpriteText;

public class StateIntro extends AbstractGameState {

	private GameObject objectTest;
	private SpriteText st, st1, st2, st3, st4, st5;

	public StateIntro(OrthographicCamera camera) {
		super(camera);
		objectTest = new GameObjectTest(100.0f, 100.0f);

		st = new SpriteText("abcde", 32, 5, 100);
		st1 = new SpriteText("fghij", 48, 5, 200);
		st2 = new SpriteText("klmno", 16, 20, 300);
		st3 = new SpriteText("pqrst", 24, 30, 400);
		st4 = new SpriteText("uvwxyz", 32, 5, 440);

		st.setOffset(10);
		st2.setOffset(30);
		st4.setOffset(1);
	}

	@Override
	public void onTouchDown(float x, float y, int pointer, int button) {
		Gdx.app.debug("StateIntro", "Tap: " + "X=" + x + " Y=" + y + "pointer="
				+ pointer + "button=" + button);
		long milliSecsToFade = 1000;

		switch (objectTest.getObjectState()) {
		case FADE_IN:
			Gdx.app.log("ObjectAction: ", "fade out");
			objectTest.fadeOut(milliSecsToFade);
			st.fadeOut(milliSecsToFade);
			st2.fadeOut(milliSecsToFade);
			st4.fadeOut(milliSecsToFade);
			break;
		case FADE_OUT:
			Gdx.app.log("ObjectAction: ", "fade in");
			objectTest.fadeIn(milliSecsToFade);
			st.fadeIn(milliSecsToFade);
			st2.fadeIn(milliSecsToFade);
			st4.fadeIn(milliSecsToFade);
			break;
		case INVISIBLE:
			Gdx.app.log("ObjectAction: ", "fade in");
			objectTest.fadeIn(milliSecsToFade);
			st.fadeIn(milliSecsToFade);
			st2.fadeIn(milliSecsToFade);
			st4.fadeIn(milliSecsToFade);
			break;
		case SOLID:
			Gdx.app.log("ObjectAction: ", "fade out");
			objectTest.fadeOut(milliSecsToFade);
			st.fadeOut(milliSecsToFade);
			st2.fadeOut(milliSecsToFade);
			st4.fadeOut(milliSecsToFade);
			break;
		default:
			break;

		}
	}

	@Override
	public void render(float delta) {
		Gdx.gl.glClearColor(0.5f, 0.5f, 0.5f, 1);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
		Gdx.gl.glEnable(GL20.GL_BLEND);
		Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

		objectTest.update(delta);
		st.update(delta);
		st2.update(delta);
		st4.update(delta);

		shapeRenderer.begin(ShapeType.Filled);
		Vector3 objectTestCoords = objectTest.getCoords2dVector();
		shapeRenderer.setColor(1.0f, 1.0f, 1.0f, objectTest.getAlpha());
		shapeRenderer.circle(objectTestCoords.x, objectTestCoords.y, 20);
		shapeRenderer.end();

		batch.begin();
		st.render(batch);
		st1.render(batch);
		st2.render(batch);
		st3.render(batch);
		st4.render(batch);
		batch.end();

		Gdx.gl.glDisable(GL20.GL_BLEND);
	}

}
